<template>
	<view class="main">
		<u-sticky>
			<subAccountQualificationAddStep :step="1" />
		</u-sticky>

		<view class="content">
			<u--form labelPosition="left" :model="merchantDetail" :rules="baseInfoModelRules" ref="baseInfoForm"
				labelWidth="87" :labelStyle="{fontSize:'26rpx', color: 'rgba(0, 0, 0, 0.7)', padding: '18rpx 0'}">
				<view class="content-item">
					<view class="content-title">上传身份信息</view>
					<u-form-item label=" " prop="certPhoto" borderBottom ref="certPhotoItem" labelWidth="0">
						<view class="upload u-flex u-row-between">
							<u-upload ref="certPhotoAUpload" 
								:fileList="certPhotoAUrlList"
								@afterRead="photoUploadAfterRead" 
								:name="photoTypeEnum.certPhotoA" :maxCount="1"
								:width="imgWidth" :height="imgHeight" 
								:maxSize="maxSize" @oversize="bannerOversize"
								@delete="deletePhoto(photoTypeEnum.certPhotoA)">
								<u--image :showLoading="true"
									:src="`${baseStaticFileUrl}/image/pages-qualification/identity-card-A.png`"
									:width="imgWidth" :height="imgHeight" />
							</u-upload>

							<u-upload ref="certPhotoBUpload" 
								:fileList="certPhotoBUrlList"
								@afterRead="photoUploadAfterRead" 
								:name="photoTypeEnum.certPhotoB" :maxCount="1"
								:width="imgWidth" :height="imgHeight" 
								:maxSize="maxSize" @oversize="bannerOversize"
								@delete="deletePhoto(photoTypeEnum.certPhotoB)">
								<u--image :showLoading="true"
									:src="`${baseStaticFileUrl}/image/pages-qualification/identity-card-B.png`"
									:width="imgWidth" :height="imgHeight" />
							</u-upload>
						</view>
					</u-form-item>
<!--					<u-form-item label=" " prop="checkStandPhotoAndHandHoldIdCard"-->
<!--						ref="checkStandPhotoAndHandHoldIdCardItem" labelWidth="0">-->
<!--						<view class="upload u-flex u-row-between">-->
<!--							<u-upload ref="handHoldIdCardUpload" -->
<!--								:fileList="handHoldIdCardUrlList"-->
<!--								@afterRead="photoUploadAfterRead" -->
<!--								:name="photoTypeEnum.handHoldIdCard" :maxCount="1"-->
<!--								:width="imgWidth" :height="imgHeight" -->
<!--								:maxSize="maxSize" @oversize="bannerOversize"-->
<!--								@delete="deletePhoto(photoTypeEnum.handHoldIdCard)">-->
<!--								<u&#45;&#45;image :showLoading="true"-->
<!--									:src="`${baseStaticFileUrl}/image/pages-qualification/hand-holdId-card.png`"-->
<!--									:width="imgWidth" :height="imgHeight"-->
<!--									@tap.stop.prevent="openUploadDemo(photoTypeEnum.handHoldIdCard)" />-->
<!--							</u-upload>-->
<!--						</view>-->
<!--					</u-form-item>-->

					<u-form-item label="身份证号" prop="principalCertNo" borderBottom ref="principalCertNoItem">
						<u--input border="none" type="idcard" placeholder="请输入身份证号" inputAlign="left" clearable
							fontSize="13" maxlength="18" v-model="merchantDetail.principalCertNo" />
					</u-form-item>
					<u-form-item label="姓名" prop="principalPerson" borderBottom ref="principalPersonItem">
						<u--input border="none" placeholder="请输入姓名" inputAlign="left" clearable fontSize="13"
							maxlength="20" v-model="merchantDetail.principalPerson" />
					</u-form-item>
					<u-form-item label="手机号" prop="contactMobile" borderBottom ref="contactMobileItem">
						<u--input border="none" type="number" placeholder="请输入手机号" inputAlign="left" clearable
							fontSize="13" maxlength="11" v-model="merchantDetail.contactMobile"
							@change="contactMobileChange" />
					</u-form-item>
					<u-form-item label="场地联系电话" prop="servicePhoneNo" ref="servicePhoneNoItem"
						rightIcon="question-circle">
						<u--input border="none" type="number" placeholder="请输入场地联系电话" inputAlign="left" clearable
							fontSize="13" maxlength="20" v-model="merchantDetail.servicePhoneNo" />
						<u-icon slot="left" name="arrow-right"></u-icon>
					</u-form-item>
				</view>

				<view class="content-item">
					<view class="content-title">上传结算信息</view>
					<u-form-item label=" " prop="bankCardAB" borderBottom ref="bankCardItem" labelWidth="0"
						v-if="merchantDetail.accountType != accountTypeEnum.CORPORATE_ACCOUNT">
						<view class="upload u-flex u-row-between">
							<u-upload ref="bankCardAUpload" 
								:fileList="bankCardAUrlList"
								@afterRead="photoUploadAfterRead" 
								:name="photoTypeEnum.bankCardA" :maxCount="1"
								:width="imgWidth" :height="imgHeight" 
								:maxSize="maxSize" @oversize="bannerOversize"
								@delete="deletePhoto(photoTypeEnum.bankCardA)">
								<u--image :showLoading="true"
									:src="`${baseStaticFileUrl}/image/pages-qualification/debit-card-A.png`"
									:width="imgWidth" :height="imgHeight" />
							</u-upload>

							<u-upload ref="bankCardBUpload" 
								:fileList="bankCardBUrlList"
								@afterRead="photoUploadAfterRead" 
								:name="photoTypeEnum.bankCardB" :maxCount="1"
								:width="imgWidth" :height="imgHeight" 
								:maxSize="maxSize" @oversize="bannerOversize"
								@delete="deletePhoto(photoTypeEnum.bankCardB)">
								<u--image :showLoading="true"
									:src="`${baseStaticFileUrl}/image/pages-qualification/debit-card-B.png`"
									:width="imgWidth" :height="imgHeight" />
							</u-upload>
						</view>
					</u-form-item>
					<u-form-item label="银行卡号" prop="bankCardNo" borderBottom ref="bankCardNoItem">
						<u--input border="none" type="number" placeholder="请输入银行卡号" inputAlign="left" clearable
							fontSize="13" maxlength="32" v-model="merchantDetail.bankCardNo" />
					</u-form-item>
					<u-form-item label="银行名称" prop="bankName" borderBottom ref="bankNameItem">
						<u--input border="none" placeholder="请输入银行名称（如:中国建设银行）" inputAlign="left" clearable
							fontSize="13" maxlength="30" v-model="merchantDetail.bankName" />
					</u-form-item>
					<u-form-item label="账户户名" prop="bankCertName" borderBottom ref="bankCertNameItem">
						<u--input border="none" placeholder="请输入账户户名" inputAlign="left" clearable fontSize="13"
							maxlength="30" v-model="merchantDetail.bankCertName" />
					</u-form-item>
					<u-form-item label="开户地区" prop="bankRegion" borderBottom ref="bankRegionItem" rightIcon=""
						@click="openBankRegion()">
						<u--input border="none" placeholder="请选择开户地区" inputAlign="left" clearable fontSize="13"
							:disabled="true" disabledColor="#fff" v-model="merchantDetail.bankRegion" />
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="联行号" prop="contactLine" ref="contactLineItem">
						<u--input border="none" type="number" placeholder="请输入联行号" inputAlign="left" clearable
							fontSize="13" maxlength="32" v-model="merchantDetail.contactLine" />
					</u-form-item>
				</view>

			</u--form>
		</view>

		<view class="footer">
			<u-button type="primary" text="下一步" :customStyle="nextStepBtnCustomStyle" @click="submit()"></u-button>
		</view>

		<pick-bank-region ref="pickBankRegion" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"
			themeColor="#007AFF"></pick-bank-region>

		<certPhotoAComponent ref="certPhotoAComponentRef" />
		<certPhotoBComponent ref="certPhotoBComponentRef" />
		<bankCardAComponent ref="bankCardAComponentRef" />
		<storeInfoComponent ref="storeInfoComponent" />
	</view>
</template>

<script>
	import subAccountQualificationAddStep from '@/components/qualification-add-step/sub-account-qualification-add-step.vue';
	import merchantDetail from '@/common/po/merchant-detail.ts';
	import certPhotoAComponent from '@/pages-qualification/base-info/cert-photo-A.vue';
	import certPhotoBComponent from '@/pages-qualification/base-info/cert-photo-B.vue';
	import bankCardAComponent from '@/pages-qualification/base-info/bank-card-A.vue';
	import storeInfoComponent from '@/components/store-info/store-info.vue';

	export default {
		components: {
			subAccountQualificationAddStep,
			certPhotoAComponent,
			certPhotoBComponent,
			bankCardAComponent,
			storeInfoComponent,
		},
		data() {
			return {
				qiNiuImgURL: this.$configPath.qiNiuImgURL,
				baseStaticFileUrl: this.$configPath.staticFileUrl,
				nextStepBtnCustomStyle: {
					width: '690rpx',
					height: '88rpx',
					borderRadius: '120rpx',
					color: '#fff',
					margin: '14rpx auto 0rpx',
				},

				maxSize: 3 * 1024 * 1024,
				imgWidth: '330rpx',
				imgHeight: '234rpx',
				merchantTypeEnum: this.$merchantTypeEnum,
				accountTypeEnum: this.$accountTypeEnum,

				certPhotoAUrlList: [],
				certPhotoBUrlList: [],
				bankCardAUrlList: [],
				bankCardBUrlList: [],
				handHoldIdCardUrlList: [],
				toUrl: '/pages-qualification/sub-account-qualification/add/synthetical-info',
				photoTypeEnum: {
					certPhotoA: 'certPhotoA',
					certPhotoB: 'certPhotoB',
					bankCardA: 'bankCardA',
					bankCardB: 'bankCardB',
					handHoldIdCard: 'handHoldIdCard',
				},

				merchantDetail: merchantDetail,
				baseInfoModelRules: {
					'certPhoto': {
						type: 'boolean',
						required: true,
						message: '请上传身份证正、反面照片',
						validator: (rule, value, callback) => {
							return value == true;
						},
					},
					'principalCertNo': {
						type: 'string',
						required: true,
						message: '请输入身份证卡号',
						len: 18,
						trigger: ['blur'],
					},
					'principalPerson': {
						type: 'string',
						required: true,
						message: '请输入姓名',
						max: 20,
						min: 2,
						trigger: ['blur'],
					},
					'contactMobile': {
						type: 'number',
						required: true,
						message: '手机号规则不正确',
						validator: (rule, value, callback) => {
							return uni.$u.test.mobile(value);
						},
						trigger: ['blur'],
					},
					'servicePhoneNo': {
						type: 'string',
						required: true,
						message: '请输入场地联系电话',
						max: 20,
						min: 6,
						trigger: ['blur'],
					},
					'bankCardNo': {
						type: 'string',
						required: true,
						message: '请输入银行卡号',
						max: 32,
						min: 8,
						trigger: ['blur'],
					},
					'bankName': {
						type: 'string',
						required: true,
						message: '请输入结算名称',
						max: 30,
						min: 4,
						trigger: ['blur'],
					},
					'bankCertName': {
						type: 'string',
						required: true,
						message: '请输入账户户名',
						max: 30,
						min: 2,
						trigger: ['blur'],
					},
					'bankRegion': {
						type: 'string',
						required: true,
						message: '请选择开户支行所在地',
					},
					'contactLine': {
						type: 'integer',
						required: true,
						message: '请输入联行号',
						max: 30,
						min: 6,
						trigger: ['blur'],
					},
					'checkStandPhotoAndHandHoldIdCard': {
						type: 'boolean',
						required: true,
						message: '请上传手持身份证照片',
						validator: (rule, value, callback) => {
							return value == true;
						},
					},
				},

				bankCardAB: {
					type: 'boolean',
					required: true,
					message: '请上传银行卡正、反面照片',
					validator: (rule, value, callback) => {
						return value == true;
					},
				},

				cityPickerValueDefault: [0, 0],

				merchantInfoUploadStateEnum: this.$merchantInfoUploadStateEnum,
			};
		},
		onReady() {
			this.$refs.baseInfoForm.setRules(this.baseInfoModelRules)
		},
		onShow() {},
		onLoad() {
			this.getUncommittedMerchantInfo();
			uni.$on('updateMerchantInfo-syntheticalInfo', this.onManageInfo)
		},
		onUnload() {
			uni.$emit('updateMerchantInfo-baseInfo', {
				data: this.merchantDetail
			})
		},
		methods: {
			// 打开上传示例
			openUploadDemo(photoType) {
				this.$refs.storeInfoComponent.showPopup(photoType);
			},
			onManageInfo(e) {
				this.updateUncommittedMerchantInfo(false, e.data)
				this.initData(e.data);
			},

			// 银行卡 正面重新上传
			bankCardAUploadAgain() {
				this.bankCardAUrlList.splice(0, 1);
				this.$nextTick(() => {
					this.$refs.bankCardAUpload.chooseFile()
				})
			},

			// 身份证 反面重新上传
			certPhotoBUploadAgain() {
				this.certPhotoBUrlList.splice(0, 1);
				this.$nextTick(() => {
					this.$refs.certPhotoBUpload.chooseFile()
				})
			},

			// 身份证 正面重新上传
			certPhotoAUploadAgain() {
				this.certPhotoAUrlList.splice(0, 1);
				this.$nextTick(() => {
					this.$refs.certPhotoAUpload.chooseFile()
				})
			},

			contactMobileChange(e) {
				this.merchantDetail.servicePhoneNo = e;
				this.servicePhoneNoValidateField();
			},

			// 获取最近一次的记录
			getUncommittedMerchantInfo() {
				this.$api('merchant.getUncommittedSubAccountMerchantInfo', null).then(res => {
					if (res.status == 0) {
						if (!this.$u.test.isEmpty(res.data)) {
							this.initData(res.data);
						}
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},

			initData(data) {
				this.merchantDetail = data;

				if (this.merchantDetail.accountType != this.accountTypeEnum.CORPORATE_ACCOUNT) {
					// 结算类型不为对公时才对银行卡正反面校验是否上传
					this.baseInfoModelRules['bankCardAB'] = this.bankCardAB;
				}

				// 身份证正面
				if (!this.$u.test.isEmpty(this.merchantDetail.certPhotoA)) {
					this.certPhotoAUrlList.length = 0;
					this.certPhotoAUrlList.push({
						status: 'success',
						message: '',
						url: this.qiNiuImgURL + getApp().formatImageSuffix(this.merchantDetail.certPhotoA)
					})
				}

				// 身份证反面
				if (!this.$u.test.isEmpty(this.merchantDetail.certPhotoB)) {
					this.certPhotoBUrlList.length = 0;
					this.certPhotoBUrlList.push({
						status: 'success',
						message: '',
						url: this.qiNiuImgURL + getApp().formatImageSuffix(this.merchantDetail.certPhotoB)
					})
				}

				// 校验身份证正反面是否都上传
				this.checkCertPhoto()


				// 银行卡正面
				if (!this.$u.test.isEmpty(this.merchantDetail.bankCardA)) {
					this.bankCardAUrlList.length = 0;
					this.bankCardAUrlList.push({
						status: 'success',
						message: '',
						url: this.qiNiuImgURL + getApp().formatImageSuffix(this.merchantDetail.bankCardA)
					})
				}
				// 银行卡反面
				if (!this.$u.test.isEmpty(this.merchantDetail.bankCardB)) {
					this.bankCardBUrlList.length = 0;
					this.bankCardBUrlList.push({
						status: 'success',
						message: '',
						url: this.qiNiuImgURL + getApp().formatImageSuffix(this.merchantDetail.bankCardB)
					})
				}

				// 校验银行卡正反面是否都上传
				this.checkBankCard();

				// 手持身份证照
				if (!this.$u.test.isEmpty(this.merchantDetail.handHoldIdCard)) {
					this.handHoldIdCardUrlList.length = 0;
					this.handHoldIdCardUrlList.push({
						status: 'success',
						message: '',
						url: this.qiNiuImgURL + getApp().formatImageSuffix(this.merchantDetail.handHoldIdCard)
					})
				}
				// 收银台照、手持身份证照
				this.checkStandPhotoAndHandHoldIdCard()
			},

			// 更新记录
			updateUncommittedMerchantInfo(isNav, data) {
				var that = this;
				this.$api('merchant.updateUncommittedSubAccountMerchantInfo', data).then(res => {
					if (res.status == 0) {
						if (isNav) {
							uni.hideLoading();
							uni.navigateTo({
								url: that.toUrl,
								fail: function(res) {
									getApp().err("跳转下一步失败:" + res.errMsg)
								}
							})
						}
					} else {
						getApp().err("信息提交不成功：" + res.msg)
					}
				}).catch(() => {
					uni.hideLoading();
				})
			},

			// 获取联行号
			getBankUnionCodeBy(bankUnionCode) {
				this.$api('bankUnionCode.getBankUnionCodeBy', bankUnionCode).then(res => {
					if (res.status == 0) {
						if (!this.$u.test.isEmpty(res.data) && !this.$u.test.isEmpty(res.data.contactLine)) {
							this.merchantDetail.contactLine = res.data.contactLine
							this.contactLineValidateField();
						}
					}
				})
			},

			openBankRegion() {
				if (this.accountTypeEnum.CORPORATE_ACCOUNT != this.merchantDetail.accountType && this.$u.test.isEmpty(this
						.merchantDetail.bankCardA)) {
					getApp().err('操作该功能前请先上传银行卡正面');
					this.bankCardABValidateField();
					return
				}

				if (this.$u.test.isEmpty(this.merchantDetail.bankName)) {
					getApp().err('操作该功能前请先输入银行卡银行名称');
					this.bankNameValidateField();
					return
				}

				if (this.$u.test.isEmpty(this.merchantDetail.bankCardNo)) {
					getApp().err('操作该功能前请先输入银行卡号');
					this.bankCardNoValidateField();
					return
				}

				this.$refs.pickBankRegion.open();
			},

			onConfirm(e) {
				// console.log("e", e)
				this.merchantDetail.bankRegion = e.label;
				this.merchantDetail.bankProvince = e.provinceCode;
				this.merchantDetail.bankCity = e.cityCode;

				let bankUnionCode = {
					bankName: this.merchantDetail.bankName,
					bankCardNo: this.merchantDetail.bankCardNo,
					bankProvince: e.labelArr[0],
					bankCity: e.labelArr[1],
					accountType: this.merchantDetail.accountType,
				}
				this.getBankUnionCodeBy(bankUnionCode);
				this.bankRegionValidateField();
			},

			submit() {
        try {
          this.$refs.baseInfoForm.validate().then(res => {
			      uni.showLoading();
            this.updateUncommittedMerchantInfo(true, this.merchantDetail);
          }).catch(error => {
            getApp().err('请按红色文字提示输入完整信息才能进行下一步')
          })
        } catch (e) {
          console.error(e.toString())
          getApp().err('提交不成功：' + e.toString())
        }
			},

			deletePhoto(photoType) {
				try {
					if (photoType == this.photoTypeEnum.certPhotoA) {
						this.merchantDetail.certPhotoA = "";
						this.merchantDetail.principalCertNo = "";
						this.merchantDetail.principalPerson = "";
						this.certPhotoAUrlList.splice(0, 1)
					} else if (photoType == this.photoTypeEnum.certPhotoB) {
						this.merchantDetail.certPhotoB = "";
						this.certPhotoBUrlList.splice(0, 1)
					} else if (photoType == this.photoTypeEnum.bankCardA) {
						this.merchantDetail.bankCardA = "";
						this.merchantDetail.bankCardNo = "";
						this.bankCardAUrlList.splice(0, 1)
					} else if (photoType == this.photoTypeEnum.bankCardB) {
						this.merchantDetail.bankCardB = "";
						this.bankCardBUrlList.splice(0, 1)
					} else if (photoType == this.photoTypeEnum.handHoldIdCard) {
						this.merchantDetail.handHoldIdCard = "";
						this.handHoldIdCardUrlList.splice(0, 1)
					} else {
						getApp().err("图片类型有误")
					}
					this.checkCertPhoto(true);
					this.checkBankCard(true);
					this.checkStandPhotoAndHandHoldIdCard(true);
				} catch (e) {
					console.error(e.toString())
					this.$helpers.toast("删除不成功");
				}
			},

			async photoUploadAfterRead(event) {
				uni.showLoading({
					title: '上传中',
					mask: true
				})
				// #ifndef H5
				let _this = this;
				if(event.file.size > 1024000){
					uni.compressImage({
						src: event.file.url,
						quality: 60,
						success: comRes => {
							_this.photoUploadAfterReadFun(event,comRes.tempFilePath);
						}
					})
				}else{
					this.photoUploadAfterReadFun(event,event.file.url);
				}
				// #endif
				
				// #ifdef H5
				this.photoUploadAfterReadFun(event,event.file.url);
				// #endif
			},
			async photoUploadAfterReadFun(event,fileUrl){
				const item = {
					url: fileUrl,
					status: 'uploading',
					message: '上传中'
				}

				if (event.name == this.photoTypeEnum.certPhotoA) {
					this.certPhotoAUrlList.push(item);

					this.photoUploadFilePromise(fileUrl, this.$photoTypeEnum.CERT_PHOTO_A).then((res) => {
						this.merchantDetail.certPhotoA = res.data.picture;

						const url = this.qiNiuImgURL + getApp().formatImageSuffix(res.data.picture);
						this.certPhotoAUrlList.splice(0, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: url
						}))

						this.merchantDetail.principalCertNo = res.data.principalCertNo;
						this.merchantDetail.principalPerson = res.data.principalPerson;

						if (
							this.merchantDetail.accountType == this.accountTypeEnum.INDIVIDUAL_ACCOUNT &&
							!this.$u.test.isEmpty(res.data.principalPerson)
						) {
							// 识别完身份证后如果结算是个人的就顺便赋值到结算账户户名
							this.merchantDetail.bankCertName = res.data.principalPerson;
							this.bankCertNameValidateField();
						}

						this.checkCertPhoto(true);

						// 上传成功，识别失败
						if (this.merchantInfoUploadStateEnum.FAILURE_TO_IDENTIFY == res.status) {
							// 调起识别失败提示，并将刚上传的图片展示给他看
							this.$refs.certPhotoAComponentRef.showPopup(url);
						}

					}).catch((err) => {
						console.error("certPhotoACatch", err)
						this.certPhotoAUrlList.splice(0, 1);
					})

				} else if (event.name == this.photoTypeEnum.certPhotoB) {
					this.certPhotoBUrlList.push(item);

					this.photoUploadFilePromise(fileUrl, this.$photoTypeEnum.CERT_PHOTO_B).then((res) => {
						this.merchantDetail.certPhotoB = res.data.picture;

						const url = this.qiNiuImgURL + getApp().formatImageSuffix(res.data.picture);
						this.certPhotoBUrlList.splice(0, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: url
						}))

						this.checkCertPhoto(true);

						// 上传成功，识别失败
						if (this.merchantInfoUploadStateEnum.FAILURE_TO_IDENTIFY == res.status) {
							// 调起识别失败提示，并将刚上传的图片展示给他看
							this.$refs.certPhotoBComponentRef.showPopup(url);
						}

					}).catch((err) => {
						console.error("certPhotoBCatch", err)
						this.certPhotoBUrlList.splice(0, 1);
					})
				} else if (event.name == this.photoTypeEnum.bankCardA) {
					this.bankCardAUrlList.push(item);

					this.photoUploadFilePromise(fileUrl, this.$photoTypeEnum.BANK_CARD_A).then((res) => {
						this.merchantDetail.bankCardA = res.data.picture;

						const url = this.qiNiuImgURL + getApp().formatImageSuffix(res.data.picture);
						this.bankCardAUrlList.splice(0, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: url
						}))

						this.merchantDetail.bankCardNo = res.data.bankCardNumber;
						this.checkBankCard(true);

						// 上传成功，识别失败
						if (this.merchantInfoUploadStateEnum.FAILURE_TO_IDENTIFY == res.status) {
							// 调起识别失败提示，并将刚上传的图片展示给他看
							this.$refs.bankCardAComponentRef.showPopup(url);
						}

					}).catch((err) => {
						console.error("bankCardACatch", err)
						this.bankCardAUrlList.splice(0, 1);
					})
				} else if (event.name == this.photoTypeEnum.bankCardB) {
					this.bankCardBUrlList.push(item);

					this.photoUploadFilePromise(fileUrl, null).then((res) => {
						this.merchantDetail.bankCardB = res.data.picture;

						const url = this.qiNiuImgURL + getApp().formatImageSuffix(res.data.picture);
						this.bankCardBUrlList.splice(0, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: url
						}))

						this.checkBankCard(true);

					}).catch((err) => {
						console.error("bankCardBCatch", err)
						this.bankCardBUrlList.splice(0, 1);
					})
				} else if (event.name == this.photoTypeEnum.handHoldIdCard) {
					this.handHoldIdCardUrlList.push(item);

					this.photoUploadFilePromise(fileUrl, null).then((res) => {
						this.merchantDetail.handHoldIdCard = res.data.picture;

						const url = this.qiNiuImgURL + getApp().formatImageSuffix(res.data.picture);
						this.handHoldIdCardUrlList.splice(0, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: url
						}))

						this.checkStandPhotoAndHandHoldIdCard(true);
					}).catch((err) => {
						console.error("handHoldIdCardCatch", err)
						this.handHoldIdCardUrlList.splice(0, 1);
					})
				} else {
					uni.hideLoading();
					this.$helpers.toast("e.name有误");
					return
				}
			},

			/**
			 *
			 * @param checked 是否校验
			 */
			checkBankCard(checked) {
				if (
					!this.$u.test.isEmpty(this.merchantDetail.bankCardA) &&
					!this.$u.test.isEmpty(this.merchantDetail.bankCardB)
				) {
					this.merchantDetail.bankCardAB = true;
				} else {
					this.merchantDetail.bankCardAB = false;
				}

				if (checked) {
					this.bankCardABValidateField();
					this.bankCardNoValidateField();
				}
			},

			checkCertPhoto(checked) {
				if (
					!this.$u.test.isEmpty(this.merchantDetail.certPhotoA) &&
					!this.$u.test.isEmpty(this.merchantDetail.certPhotoB)
				) {
					this.merchantDetail.certPhoto = true;
				} else {
					this.merchantDetail.certPhoto = false;
				}

				if (checked) {
					this.certPhotoValidateField();
					this.principalCertNoValidateField();
					this.principalPersonValidateField();
				}

			},

			checkStandPhotoAndHandHoldIdCard(checked) {
				if (!this.$u.test.isEmpty(this.merchantDetail.handHoldIdCard)) {
					this.merchantDetail.checkStandPhotoAndHandHoldIdCard = true;
				} else {
					this.merchantDetail.checkStandPhotoAndHandHoldIdCard = false;
				}

				if (checked) {
					this.checkStandPhotoAndHandHoldIdCardValidateField();
				}
			},

			upload(photoType) {
				this.$nextTick(() => {
					if (photoType == this.photoTypeEnum.handHoldIdCard) {
						this.$refs.handHoldIdCardUpload.chooseFile()
					} else {
						getApp().err("启动上传照片不成功")
					}
				})
			},

			photoUploadFilePromise(fileUrl, photoType) {
				// console.log("photoType", photoType)
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$configPath.baseURL + '/api/merchant/merchantRegisterUploadByApplet',
						filePath: fileUrl,
						name: 'file',
						header: {
							Authorization: 'Bearer ' + this.$store.getters.GET_VALUE("GET_TOKEN")
						},
						timeout: 6000,
						formData: {
							photoType: photoType
						},
						success: (res) => {
							uni.hideLoading();
							let data = JSON.parse(res.data);
							if (this.merchantInfoUploadStateEnum.SUCCESS == data.status) {
								this.$helpers.toast("上传成功", "success");
								resolve(data);
							} else if (this.merchantInfoUploadStateEnum.FAILURE_TO_IDENTIFY == data
								.status) {
								//上传成功，识别失败
								resolve(data);
							} else {
								reject(data)
								getApp().err("上传不成功，" + data.msg);
							}
						},
						fail: (res) => {
							uni.hideLoading();
							let errMsg = res.errMsg;
							if (uni.$u.test.contains(errMsg, 'timeout')) {
								errMsg = "请求超时，请重新上传";
							}
							getApp().err(errMsg);
							reject("请求超时，请重新上传")
						},
					});
				})
			},


			certPhotoValidateField() {
				this.$refs.baseInfoForm.validateField('certPhoto', err => {
					// console.log("err", err)
				})
			},
			principalCertNoValidateField() {
				this.$refs.baseInfoForm.validateField('principalCertNo', err => {
					// console.log("err", err)
				})
			},
			principalPersonValidateField() {
				this.$refs.baseInfoForm.validateField('principalPerson', err => {
					// console.log("err", err)
				})
			},
			contactMobileValidateField() {
				this.$refs.baseInfoForm.validateField('contactMobile', err => {
					// console.log("err", err)
				})
			},
			servicePhoneNoValidateField() {
				this.$refs.baseInfoForm.validateField('servicePhoneNo', err => {
					// console.log("err", err)
				})
			},
			bankCardABValidateField() {
				this.$refs.baseInfoForm.validateField('bankCardAB', err => {
					// console.log("err", err)
				})
			},
			bankCardNoValidateField() {
				this.$refs.baseInfoForm.validateField('bankCardNo', err => {
					// console.log("err", err)
				})
			},
			bankNameValidateField() {
				this.$refs.baseInfoForm.validateField('bankName', err => {
					// console.log("err", err)
				})
			},
			bankCertNameValidateField() {
				this.$refs.baseInfoForm.validateField('bankCertName', err => {
					// console.log("err", err)
				})
			},
			bankRegionValidateField() {
				this.$refs.baseInfoForm.validateField('bankRegion', err => {
					// console.log("err", err)
				})
			},
			contactLineValidateField() {
				this.$refs.baseInfoForm.validateField('contactLine', err => {
					// console.log("err", err)
				})
			},
			checkStandPhotoAndHandHoldIdCardValidateField() {
				this.$refs.baseInfoForm.validateField('checkStandPhotoAndHandHoldIdCard', err => {
					// console.log("err", err)
				})
			},

			bannerOversize() {
				getApp().err("图片大小超限，最大3MB。如图片来自相册，建议使用直接拍摄");
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.content {

			.content-item {
				background-color: $uni-bg-color;
				margin-bottom: 20rpx;
				padding: 24rpx 30rpx;

				.content-title {
					color: rgb(13, 13, 13);
					font-size: 30rpx;
				}

				.upload {
					padding: 30rpx 0rpx 12rpx;
				}
			}
		}

		.footer {
			width: 100%;
			margin-top: 94rpx;
			padding-bottom: 74rpx;
		}
	}

	/deep/ .u-input__content__field-wrapper__field {
		width: 450rpx;
	}
</style>
